﻿<div ms-controller="tempview">

    <div class="sui-form form-inline" style="padding-top:5px;">
        城市：
        <select class="input-medium input-xfat" ms-duplex="Client">
            <option value="0">请选择城市</option>
            <option ms-repeat-el="ClientList" ms-attr-value="el.ID">{{el.CodeName}}</option>
        </select>
        社区：
        <select class="input-medium input-xfat" ms-duplex="SQID">
            <option value="">请选择社区</option>
            <option ms-repeat-el="SheQuList" ms-attr-value="el.ID">{{el.Title}}</option>
        </select>
        状态：
        <select class="input-medium input-xfat" ms-duplex="status">
            <option value="">所有</option>
            <option value="0">未支付</option>
            <option value="1">已支付</option>
            <option value="2">已发货</option>
            <option value="3">确认收货</option>
            <option value="9">已取消</option>
        </select>
        <input type="text" ms-duplex="searchkey" placeholder="关键字搜索" class="input-large input-xfat" />
        <a class="sui-btn btn-large btn-primary" style="margin-left:10px;" ms-click="GetLIST()">查询</a>
    </div>

    <div>

        <table class="sui-table table-bordered" ms-repeat-el="ListData">
            <thead>
                <tr>
                    <th colspan="5">
                        <label class="pull-left">
                            订单编号：{{el.ID}}
                        <span>下单账号：{{el.username}}</span><span style="padding-left:5px;">{{el.truename}}</span>
                         <span style="padding-left:10px;">收货人：{{el.Receiver}}</span><span style="padding-left:5px;">{{el.Telephone}}</span>
                            <span style="padding-left:5px;">{{el.Province}}{{el.City}}{{el.County}}{{el.Address}}</span>
                        </label><span class="pull-right">下单时间：{{el.CRTime}}，总金额：<span style="color:red;">¥{{el.SumPrice}}</span></span>
                    </th>
                </tr>
            </thead>
            <tbody>
                <tr ms-repeat-im="el.SubItem">
                    <td width="50%">
                        <div class="typographic">
                            <img ms-attr-src="ComFunJS.FilePath(im.ImgUrl,'/80/80')"><a href="#" class="block-text">{{im.Title}}</a><span><span style="color:#ff0000;">¥{{im.Price1}}×{{im.Qty}}</span></span>
                        </div>
                    </td>
                    <td width="10%" class="center" style="color:#ff0000;">¥{{im.Price1*im.Qty}}</td>
                    <td width="10%" class="center">
                        <ul class="unstyled">
                            <li>{{ShowStatus(im.Status)}}</li>
                            <!--<li><a href="#">订单详情</a></li>
                            <li><a href="#">对方已评</a></li>-->
                        </ul>
                    </td>
                    <td width="20%" class="center">
                        <p style="margin:0;text-align:left;">快递：{{im.ExpressName}} </p>
                        <p style="margin:0;text-align:left;">单号：{{im.ExpressNo}} </p>
                        <p style="margin:0;text-align:left;">发货时间：{{im.SendTime}} </p>
                    </td>
                    <td width="10%" class="center">
                        <ul class="unstyled" >
                            <li><a href="javascript:void(0)" ms-click="SendGood(im)" ms-if="im.Status==1">发货</a></li>
                            <li><a href="javascript:void(0)" ms-click="Cancel(im)" style="color:#ff0000;" ms-if="im.Status==1">取消</a></li>
                        </ul>
                    </td>
                </tr>

            </tbody>
        </table>
    </div>
   

</div>
<script type="text/javascript">
    var tempmodel = avalon.define({
        $id: "tempview",
        ClientList: [],
        SheQuList:[],
        Client: "0",
        SQID:"",
        status: "",
        Type2: "",
        TypeList1: [],
        TypeList2: [],
        IsShelf: "",
        ADD2: function (el) {
            top.ComFunJS.winShowForm("/admin/base/add2.html?funcode=" + model.FunCode + "&ID=" + el.ID, "查看");
        },
        Init: function () {
            $.getJSON("/adapi/base/client/list", function (r) {
                if (r.error == "") {
                    tempmodel.ClientList = r.result;
                }

            })
            tempmodel.GetLIST();
        },
        GetLIST: function () {
            model.page.pageindex = 1;
            model.ListData.clear();
            $.getJSON("/adapi/order/list/" + tempmodel.Client, { pageindex: model.page.pageindex, pagesize: model.page.pagesize, "searchkey": model.searchkey, "status": tempmodel.status, "sqid": tempmodel.SQID }, function (r) {
                if (r.error == "") {
                    model.ListData = r.result;
                    model.total = r.total;

                    $("#pageDiv").pagination({  //分页容器
                        styleClass: ['sui-pagination'],  //分页样式
                        //showCtrl: false,
                        displayPage: 6,
                        itemsCount: r.total,
                        pageSize: model.page.pagesize,
                        onSelect: function (num) {
                            model.page.pageindex = num;
                            $.getJSON("/adapi/order/list/" + tempmodel.Client, { pageindex: model.page.pageindex, pagesize: model.page.pagesize, "searchkey": model.searchkey, "status": tempmodel.status, "sqid": tempmodel.SQID }, function (r) {
                                model.ListData.clear();
                                model.ListData = r.result;
                            })
                        }
                    })

                    $('#pageDiv').pagination('updateItemsCount', r.total, 1);
                }
            })
        },
        ShowStatus: function (s) {
            var st = "";
            switch (s) {
                case 0:
                    st = "未支付";
                    break;
                case 1:
                    st = "已支付";
                    break;
                case 2:
                    st = "已发货";
                    break;
                case 3:
                    st = "确认收货";
                    break;
                case 9:
                    st = "已取消";
                    break;
            }
            return st;
        },
        SendGood: function (el) {

            top.ComFunJS.winShowFormBtn("填写快递信息", "/admin/add/kuaidi.html?v=1", "500", "300", function (layero, layindex) {
                
                var body = top.layer.getChildFrame('body', layindex);
                var sendtype = body.find("#sendtype").val();
                var sendkd = body.find("#sendkd").val();
                var sendno = body.find("#sendno").val();
                if (sendtype == "0" && !sendno) {
                    top.ComFunJS.winShowMsg("请输入快递单号");
                    return;
                }

                $.getJSON("/adapi/order/send/" + el.ID, { sendtype: sendtype, sendkd: sendkd, sendno: sendno }, function (r) {
                    if (r.error == "") {
                        el.Status = 2;
                        el.ExpressName = r.result.ExpressName;
                        el.ExpressNo = r.result.ExpressNo;
                        el.SendTime = r.result.SendTime;
                        top.ComFunJS.close(layindex);
                        top.ComFunJS.winShowMsg("发货成功");
                    } else {
                        top.ComFunJS.winShowAlert(r.error);
                    }

                })

            })
        },
        Cancel: function (el) {
            if (el) {
                top.ComFunJS.winShowConfirm("<span style='color:red;'>确定要取消订单吗?<span>", function () {
                    $.getJSON("/adapi/order/cancel/" + el.ID, function (r) {
                        if (r.error == "") {
                            el.Status = 9;
                            top.ComFunJS.winShowMsg("取消成功");

                        }
                    })
                })
            }

        }


    })

    tempmodel.$watch("Client", function () {
        tempmodel.SheQuList.clear();
        tempmodel.SQID = "";
        if (tempmodel.Client) {
            $.getJSON("/adapi/shequ/list2/" + tempmodel.Client, function (r) {
                tempmodel.SheQuList = r.result;
            })
        }

    })


</script>

